package com.family.web.controller.pedigree;


import com.family.common.annotation.Log;
import com.family.common.core.controller.BaseController;
import com.family.common.core.domain.AjaxResult;
import com.family.common.core.page.TableDataInfo;
import com.family.common.enums.BusinessType;
import com.family.pedigree.domain.FamilyTreeNode;
import com.family.pedigree.service.IFamilyTreeNodeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 家族树节点 前端控制器
 * </p>
 *
 * @author forever
 * @since 2024-11-24
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/family/tree/node")
public class FamilyTreeNodeController extends BaseController {

    private final IFamilyTreeNodeService familyTreeNodeService;

    @Log(title = "添加节点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FamilyTreeNode treeNode){

        return success(familyTreeNodeService.add(treeNode));
    }

    @Log(title = "修改节点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FamilyTreeNode treeNode){

        return success(familyTreeNodeService.edit(treeNode));
    }

    @GetMapping("/list")
    public TableDataInfo getList(FamilyTreeNode treeNode){
        startPage();
        return getDataTable(familyTreeNodeService.getList(treeNode));
    }

    @DeleteMapping("/{nodeId}")
    public AjaxResult delById(@PathVariable Long nodeId){
        familyTreeNodeService.delById(nodeId);
        return success();
    }

    @GetMapping("/{nodeId}")
    public AjaxResult getById(@PathVariable("nodeId") Long nodeId){
        return success(familyTreeNodeService.queryById(nodeId));
    }

    @GetMapping("/relation/six/{nodeId}")
    public AjaxResult getRelationSix(@PathVariable("nodeId") Long nodeId){
        return success(familyTreeNodeService.getRelationSix(nodeId));
    }
}
